package com.day23.ComparratorDemo;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;

public class ComparatorDemo {
    public static void main(String[] args)
    {
        ArrayList<String> array = new ArrayList<String>();
        array.add("ccc");
        array.add("aa");
        array.add("b");
        array.add("ddd");
        System.out.println("排序前："+array);
        Collections.sort(array,getComparator());
        System.out.println("排序后："+array);
    }
    private static Comparator<String> getComparator()
    {
        return (s1,s2)->s1.length()-s2.length();
    }
}
